package org.dromara.learning_xq.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.dromara.learning_xq.entity.AsJobManagement;
import org.dromara.learning_xq.service.AsJobManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/asJobManagement")
@Tag(name = "作业管理")
public class AsJobManagementController {

    @Autowired
    private AsJobManagementService asjobManagementService;


    /**
     * 作业管理查询全部操作
     *
     * @return 包含查询结果的响应体
     */
    @PostMapping("/selverAsJobManagement")
    @Operation(summary = "作业管理查询全部")
    public ResponseEntity<Map<String, Object>> selverAsJobManagement() {
        Map<String, Object> response = new HashMap<>();

        try {
            // 调用服务查询作业管理列表
            List<AsJobManagement> jobManagementList = asjobManagementService.selverAsJobManagement();

            // 查询成功，设置响应数据
            response.put("success", true);
            response.put("data", jobManagementList);
            response.put("message", "查询成功");
            return ResponseEntity.ok(response);

        } catch (Exception e) {
            // 查询失败，设置响应数据
            response.put("success", false);
            response.put("message", "查询失败: " + e.getMessage());
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
        }
    }


    /**
     * 作业管理条件查询接口
     * 通过指定的查询条件，获取作业管理列表
     *
     * @param asJobManagement 作业管理的查询条件对象
     * @return 包含查询结果的响应对象
     */
    @PostMapping("/selverAsJobManagementCondition")
    @Operation(summary = "作业管理条件查询")
    public ResponseEntity<Map<String, Object>> selverAsJobManagementCondition(@RequestBody AsJobManagement asJobManagement) {
        Map<String, Object> response = new HashMap<>();

        try {
            // 调用服务层方法，根据查询条件获取作业管理列表
            List<AsJobManagement> jobManagementList = asjobManagementService.selverAsJobManagementCondition(asJobManagement);

            // 查询成功，设置响应数据
            response.put("success", true);
            response.put("data", jobManagementList);
            response.put("message", "查询成功");
            return ResponseEntity.ok(response);

        } catch (Exception e) {
            // 查询失败，设置响应数据
            response.put("success", false);
            response.put("message", "查询失败: " + e.getMessage());
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
        }
    }

}

